<?php
/**
 * @Author: Marte
 * @Date:   2017-08-25 09:21:48
 * @Last Modified by:   Marte
 * @Last Modified time: 2017-08-29 14:51:37
 */
header('content-type:text/html;charset:utf-8');
require_once 'include/init.php';
require_once 'core/user.php';
function login2(){
   $username=$_POST['username'];
   $username=addslashes($username);
   $password=md5($_POST['password']);
   $sql="select * from user where username='{$username}' and password='{$password}'";
   //echo $sql;die();
   $row=getRow($sql);
   if($row){
   $_SESSION['username']=$row['username'];

alertMsg('登陆成功','index.php');
   }else{
    alertMsg('登录失败，请重新登录','login.php');
}
}


function userOut($id){

if(isset($_GET['userOut'])){
   unset($_SESSION['username']);
   unset($_SESSION['password']);
alertMsg('已经退出','login,php');
}

}


function reg(){
    $pic=uploadfile('admin/userpic/');
     $_POST['myfile']=$pic[0]['name'];
     $_POST['password']=md5($_POST['password']);
     if(insert('user',$_POST)){
alertMsg('注册用户成功','login.php');
     }else{

alertMsg('请重新注册','reg.php');




}
}
$act=isset($_GET['act'])?$_GET['act']:null;
$id=isset($_GET['id'])?$_GET['id']:null;
if($act=='login2'){
    login2();
}else if($act=='userOut'){
    $id=$_GET['id'];
    userOut();
}else if($act=='reg'){
    reg();
}









?>